package com.tjvib.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.tjvib.R;
import com.tjvib.util.ToastUtil;
import com.tjvib.widget.CirclePgBar;

public class LoadingDialog extends Dialog {
    public LoadingDialog(@NonNull Context context) {
        super(context);
    }

    public LoadingDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected LoadingDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public void showDialog(Context context, String con) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
        this.setContentView(view);
        this.setCanceledOnTouchOutside(false);
        this.show();

        TextView dialog_load_tv = this.findViewById(R.id.dialog_load_tv);
        dialog_load_tv.setText(con);
        CirclePgBar dialog_load_cpb = this.findViewById(R.id.dialog_load_cpb);
        dialog_load_cpb.setProgress(100, 10000);
        dialog_load_cpb.setOnCircleProgressListener(progress -> {
            if (progress == 100) {
                dismiss();
            }
            return false;
        });
    }

    public void showDialog(Context context, String con, int sec) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
        this.setContentView(view);
        this.setCanceledOnTouchOutside(false);
        this.show();

        TextView dialog_load_tv = this.findViewById(R.id.dialog_load_tv);
        dialog_load_tv.setText(con);
        CirclePgBar dialog_load_cpb = this.findViewById(R.id.dialog_load_cpb);
        dialog_load_cpb.setProgress(100, sec * 1000);
        dialog_load_cpb.setOnCircleProgressListener(progress -> {
            if (progress == 100) {
                dismiss();
            }
            return false;
        });
    }
}
